<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<%-- <base href="<%=basePath%>"> --%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>门户基本页</title>
<script src="<%=basePath%>assets/js/jquery-1.10.1.min.js"></script>
<link href="../assets/css/reset.css" rel="stylesheet" />
<link href="../assets/css/tabs.css" rel="stylesheet" />
<link href="../assets/css/queryUnit.css" rel="stylesheet" />
<script src="<%=basePath%>assets/js/html5shiv.min.js"></script>
<script src="<%=basePath%>assets/js/respond.min.js"></script>
<script src="<%=basePath%>assets/js/portal.js"></script>
<script src="<%=basePath%>assets/js/cn.js"></script>
<script src="<%=basePath%>assets/js/core.js"></script>
<script src="<%=basePath%>assets/js/global.js"></script>
<script src="<%=basePath%>assets/js/mousewheel.js"></script>
<script src="<%=basePath%>assets/js/tabs.js"></script>
<link href="<%=basePath%>${cssPath}" rel="stylesheet" />
<style>
	.left{
	   display: inline;
	   float: left;
	   margin-right: 20px;
	   overflow: hidden;
	   width: 280px;
	}
	
.right {
    font-size: 14px;
}
.right {
    display: inline;
    float: right;
    left: 280px;
    overflow: hidden;
    width: 700px;
}
.blank_left, .blank_hd {
    background: rgba(0, 0, 0, 0) url("../../img/nw_blank_hd_left.jpg") repeat-x scroll left top;
    text-align: center;
}
.blank_hd {
    font-size: 14px;
    font-weight: bold;
    height: 35px;
    line-height: 35px;
    overflow: hidden;
}
</style>

<script type="text/javascript" >

function fixSize(){
	/*var w_h = window.innerHeight;
		var top_h = $('.hd_top').outerHeight();
		var logo_h = $('.header').outerHeight();
		var menu_h = $('#menuShow').outerHeight();
		var foot_h = $('.footer').outerHeight();
		var con_h = w_h - top_h - logo_h - menu_h - foot_h;*/
		
		var con_h = document.body.scrollHeight;
	    //	$('.ifra').css('height',con_h+'px');
			$('.ifra').css('height','580px');
	//	console.log('con_h: '+con_h);
	/*	if(con_h<400){
			$('.ui_wrap').addClass('unit_icon-wrap');
		}else{
			$('.ui_wrap').removeClass('unit_icon-wrap');
		}*/
		

			
// 		console.log('win_h:'+w_h);
// 		console.log("ifr_h: "+$('.ifra').height());
}



var  laycode ;	
$(document).ready(function() {
		$("#theme").load('<%=basePath%>${templatePath}', function(){
			var portal_id=${portal_id};
			findLaycode(portal_id);	
			var userName = '${userName}';
			$.ajax({
				type:"POST",
				url:'<%=basePath%>portal/showPortal.do',
				dataType:"text",
				async: true,
				global: false,
				success:function(data){
					/* 显示日期 */
					
				//	$(".header_right").append("<p><span>今天是"+datetime+"</span><span class='space'>|</span><a href='#'>设为首页</a></p>"); 									
			
					appendHeader(userName);
					var obj = eval ("(" + data + ")");
				
					var htmlstr = "";
					var str1 = "";
					var strblank="";				
					var footercon = "${footerContent}";		
					document.getElementById("tempLogo").src="<%=basePath%>${logoUrl}";					
					if(laycode==1){
						
						for(var i=0;i<obj.length;i++){
							if(obj[i].portletName=="福建磁贴容器"){
								
								var blankString="<div class='blank'></div>";
								$(".container").append(blankString);
								strblank="<div class='tabs blank_info' id='tabs' style=''></div>";
								$(".blank").append(strblank);
								
								var dd = [], i=0; 
								var tabs = $('.tabs');	
								for(i=0; i<1; i++){
									var a = {
										code: 'tab工作台',
										title: '工作台',
										closeable: i>0,
										el: '<iframe id="tile" name="tabs-ifra" class="ifra tabs-ifra" src='+obj[i].viewUrl+' frameborder="no" border="0" width="100%"></iframe>'
										//el: '<iframe name="tabs-ifra" class="ifra tabs-ifra" src='+url+' frameborder="no" border="0" width="100%"></iframe>'

									};
									dd.push(a);
								}
								tabs.mac('tabs', {
									tabWidth: 80, //Use fix width
									items: dd,
									onCloseTab: function(me, c, a){
										tnCbx.find('[value=' + c + ']').remove();
										return true;
									}
								}).selectFirst();
								var thd = tabs.children('.head'), thm = thd.children('.main');
								thd.mousewheel(function(e, delta, deltaX, deltaY){
									thm.scrollLeft(thm.scrollLeft() - deltaY * 40);
									return false;
								});
								var tnCbx = $('#tabNoCbx').change(function(){
									tabs.select($(this).val());
								});
						
							}
							else{
								strblank="<div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe class='ifra' src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%'></iframe></div>";
								 $(".blank").append(strblank);
							}
							
						}
						//改变iframe高度
						fixSize();
						//动态改变iframe高度
						window.onresize = function(){
							fixSize();
						}
					}
					
					if(laycode==2){
					var leftString="<div class='left' id='left11'></div>";
					var rightString="<div class='right'></div>";					
					$(".container").append(leftString);
					$(".container").append(rightString); 
							
					for(var i=0;i<obj.length;i++){		
					
						str1= "<div class='blank_left'><div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div></div>";
					 	htmlstr="<div class='blank_right'><div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div></div>";     
						if(obj[i].pagerow==1){	
							 $(".left").append(str1);						
						}
						else if(obj[i].pagerow==2){	 
							 $(".right").append(htmlstr);							
						}			
					}
				}			
			
					if(laycode==3){
		
						var leftString="<div class='leftblank' ></div>";
						var rightString="<div class='rightblank'></div>";
						var blankString="<div class='centerblank'></div>";
						$(".container").append(leftString);
						$(".container").append(rightString); 
						$(".container").append(blankString); 
					
						for(var i=0;i<obj.length;i++){
							str1= "<div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div>";
						 	htmlstr="<div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div>";  
						 	strblank="<div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div>";
						
						if(obj[i].pagerow==1){	
							 $(".leftblank").append(str1);						
						}
						else if(obj[i].pagerow==2){	 
							 $(".rightblank").append(htmlstr);						
						}	
						else if(obj[i].pagerow==3){	 
							 $(".centerblank").append(strblank);						
						}
						}
					}
						$(".footer").append(footercon);
						menuList();
						showMenu(portal_id);
						
						var queryUnit = '<div class="clearfix" style=" width: 1000px;height:30px;margin:auto;margin-bottom:10px;" >'
						    + '<div style="border:1px solid #ccc; border-radius: 4px;width:100%;height:100%;background:white">'
							+ '<input id="input-param" style="border:none;display:block;float: left;margin-left:3px;width:970px;height: 100%;" type="text" />'
							+'<span id="query-btn" class="glyphicon glyphicon-search" style="display: block;float: left; color: #5db2ff; font-size: 15px;margin-top: 7.5px;cursor:pointer;"></span></div></div>';
							
						
						$(queryUnit).insertBefore(".container");
					},
						error:function(){
						alert("加载失败，请重试");
						}				
			});	
		});
});
	
	
//点击综合查询按钮
$(document).on("click","#query-btn",function(){
	$(".tt>.item").each(function(){
		if($(this).attr('name')=="tab综合查询"){
			$(this).children(".xbtn").children(".icon-close").click();
			return true;
		}
	});
	
   var userId = '${loginUserId}';
   var param = $("#input-param").val();
   var url = 'http://198.10.10.133:7001/RMS/component/multipleWSDL.action?userId='+userId+'&param='+param;
   openUrl("综合查询",url);
});




//编辑内容的控制显示列数的js
function appendHeader(userName){	
	var datetime = CurentTime();
	$(".header_right").append("<p><span>欢迎您："+userName+" </span><a href='<%=basePath%>portalAdmin/portallog.do'> 登出  </a><span> 今天是"+datetime+"</span><span class='space'>|</span><a href='#'>设为首页</a></p>");		
}

	//编辑内容的控制显示列数的js
function findLaycode(portal_id){	 	
	$.ajax({
		type:"post",
		url:"<%=basePath%>portalAdmin/findByPortalid.do",
		data:{portal_id:portal_id},
		async: false,
		success:function(datas){			
		var arr=eval ("("+datas+")");
	     var layid=arr.pagelayout;   
	     if(layid==1){
	    	 laycode=1;
	     }else if(layid==2){
	    	 laycode=2;
	   
	     }else{
	    	 laycode=3;
	     }
	 }
	}); 
}
		
	//编辑内容的控制显示列数的js
function showMenu(id){
	var userId = '${loginUserId}';
	$.ajax({
		type:"post",
		url:"<%=basePath%>portal/showMenu.do",
		data:{portal_id:id},
		async: true,
		success:function(datas){
			if(datas== "" || datas == null){
				var strMenu = "<li class='menu_cur'><span class='menu_space'></span><a href='#' onclick='BReturn()'>工作台</a></li>";
				$('.menu').append(strMenu);
			}else{
						
				var arr=eval ("("+datas+")");
		     
				var strMenu = "<li class='menu_cur'><span class='menu_space'></span><a href='javascript:void(0);' onclick='BReturn()'>工作台</a></li>";
				for(var i=0;i<arr.list.length;i++){
					if(arr.list[i].one.businessType=="磁贴权限管理"){
						var url = "http://198.10.10.133:7001/RMS/component/auth.action?userId="+userId;
						strMenu+= "<li><span class='menu_space'></span> <a href='javascript:void(0);' onclick='openUrl(\"磁贴权限管理\",\""+url+"\");'>"+arr.list[i].one.businessType+"</a>";

					}else{
						strMenu+= "<li><span class='menu_space'></span> <a href='javascript:void(0);'>"+arr.list[i].one.businessType+"</a>";
					}
					if(arr.list[i].twoList!=null){
						strMenu += "<div class='menu_sub' style='display:none;'>";

						for(var j=0;j<arr.list[i].twoList.length;j++) {
							if(arr.list[i].twoList[j].url!=undefined&&arr.list[i].twoList[j].appId!="001"){
								if(arr.list[i].twoList[j].url.indexOf("http://")>=0){
							 		strMenu += "<a href='javascript:void(0);'  onclick='openUrl(\""+arr.list[i].twoList[j].appName+"\",\""+arr.list[i].twoList[j].url+"\",\""+arr.list[i].twoList[j].appId+"\");menuSite(\""+arr.list[i].one.businessType+"\",\""+arr.list[i].twoList[j].appName+"\")'>"+arr.list[i].twoList[j].appName+"</a>";
								}else{
							 		strMenu += "<a href='javascript:void(0);'  onclick='openUrl(\""+arr.list[i].twoList[j].appName+"\",\"http://"+arr.list[i].twoList[j].url+"\",\""+arr.list[i].twoList[j].appId+"\");menuSite(\""+arr.list[i].one.businessType+"\",\""+arr.list[i].twoList[j].appName+"\")'>"+arr.list[i].twoList[j].appName+"</a>";
								}
							}
					 	}
						strMenu += "</div>";
					}
					strMenu += "</li>";
				}		 
				
				 $('.menu').append(strMenu);
				 
				  $(".menu li").mousemove(function() {
					
						
						$(this).find('div').show();
						
					});
					$(".menu li").mouseleave(function() {
						
						$(this).find('div').hide();
						
					}); 
				}
	 		}
	  }); 
}
	
	
function menuSite(businessType,appName){
		$(".menu_site").empty();	
		$(".menu_site").append("协同管理平台","->"+appName); 
		
}
function menuList(){
		$(".menu_site").empty();	
		$(".menu_site").append("协同管理平台->工作台"); 
		
}
function BReturn(){
		parent.location.reload();   
}
			
function openUrl(name,url,appId){
	if(appId=="08054"||appId=="08053"||appId=="0804001"){
		window.open(url);
	}else{
		addTabs(name,url);
		//旧版
		/* $(".container").empty();	
		$('.container').append("<div><iframe class='ifra' src='"+url+"' frameborder='no' border='0' width='100%'></iframe></div>"); */
		//改变iframe高度
		fixSize();
		//动态改变iframe高度
		window.onresize = function(){
			fixSize();
		}
	}
}		
	
</script>

<script type="text/javascript">			     

//关闭tab
$(document).on("click",".xbtn .icon-close",function(e){
	var item = $(this).parent(".xbtn").parent(".item");
	var name = item.attr("name");
	item.remove();
	$(".body .main").filter('[name="'+name+'"]').remove();
	adjustT();
	$(".tabs .body .main:last").show();
	$(".tt .item:last").addClass("selected");
	/* $(".tt .item").filter('[name="tab工作台"]').addClass("selected");
	$(".body .main").filter('[name="tab工作台"]').css("display","block"); */
	e.stopPropagation();

});   

//刷新tab
$(document).on("click",".refresh_btn",function(e){
	var url = $(this).attr("refresh-url");
	var name = $(this).parent(".main").text();
	$("#ifra"+name).attr("src",url);
	e.stopPropagation();
});

$(document).on("click",".tt .item",function(){
	hideALlIfra();
	$(this).addClass("selected");
	var name = $(this).attr("name");
	$(".body .main").filter('[name="'+name+'"]').show();
});

function hideALlIfra(){
	$(".tt .item").each(function(){
		$(this).removeClass("selected");
	});
	$(".body .main").each(function(){
		$(this).hide();
	});
}




//点击磁贴

function addTabs(name,url){
	console.log("####");
	var hadAdd = false;
	//已打开，不添加
	$(".tt").children(".item").each(function(){
		if($(this).children(".main").text()==name){
			hadAdd = true;
			hideALlIfra();
			$(this).addClass("selected");
			$(".body .main").filter('[name="tab'+name+'"]').show();
			adjustT();
		}
	});
	//未打开，添加
	if(!hadAdd){
		hideALlIfra();
		var str1='<div class="item normal closeable selected" name="tab'+name+'" style="height: 26px;"><div class="left"></div><div class="main" style="width: 100px;">'+name+'<span class="glyphicon glyphicon-refresh refresh_btn" refresh-url="'+url+'" style="font-size:10px;color:#666;display:inline-block;margin:0 3px"></span></div><div class="xbtn"><span class="icon icon-close"></span></div><div class="right"></div></div>';
		$(".tt").append(str1);
		var str2='<div class="main tabs-hidden" name="tab'+name+'" style="display: block;"><iframe class="tabs-ifra ifra" id="ifra'+name+'" style="width:100%;height:100%;" src="'+url+'"></iframe></div>';
		$(".tabs").children('.body').append(str2);	
		adjustT();
	}
	fixSize();
}	

//添加左右调整
function adjustT(){
	var hd = $(".tabs .head");
	var hl = $(".tabs .head .left");
	var hr = $(".tabs .head .right");
	var ht = $(".tabs .head .main .tt");
	var hm = $(".tabs>.head>.main");

	var item_last = $(".tt .item:last");


	if (hd.width()) {
		var hd_width = hd.width();
		if(hm.width()<hd_width){
			hd_width = hm.width();
		}
		// var b = hd.width()<=ht.width();
		var b = hd_width<=ht.width();
		if(b){
			hm.scrollLeft(hm.scrollLeft()+item_last.position().left-hm.position().left);
		}
		hl.toggle(b);
		hr.toggle(b);
		hm.width(hd.width() - (b ? hl.width() * 2 + 2 : 0));
	}
	$(".tt .item .left").show();
	$(".tt .item .right").show();
}

</script>

</head>
	   <div id="theme"></div>	   	
</html>
